import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 无限加载

void main() {
  runApp(MaterialApp(
    home: PageviewFulll(),
  ));
}

class PageviewFulll extends StatefulWidget {
  const PageviewFulll({super.key});

  @override
  State<PageviewFulll> createState() => _PageviewFulllState();
}

class _PageviewFulllState extends State<PageviewFulll> {
  List<Widget> l = [];

  PageController _pageController = PageController(initialPage: 0);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 初始化数据
    getchild();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Pageview的使用'),
        ),
        body: PageView(
          controller: _pageController,
          onPageChanged: (index) {
            print('华东到了第 $index 页');

            if (index == 8) {
              getchild();
            }
          },
          children: l,
        ));
  }

  List<Widget> getchild() {
    for (var i = 0; i <= 10; i++) {
      l.add(Center(
        child: Text(
          '这是第 ${l.length + 1} 页',
          style: TextStyle(fontSize: 24),
        ),
      ));
    }
    return l;
  }
}
